package com.rd.student.jiaji.class3.sunguowei.Questions;

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;

public class six {
    public static void main(String[] args) {
        LinkedList list=new LinkedList();
        Student name=new Student("liusan",20,90);
        Student name1=new Student("lisi",22,90);
        Student name2=new Student("wangwu",20,99);
        Student name3=new Student("sunliu",22,100);
        list.add(name);
        list.add(name1);
        list.add(name2);
        list.add(name3);


        Collections.sort(list, new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                Student d1 = (Student) o1;
                Student d2 = (Student) o2;

                if (d1.score < d2.score) {
                    return 1;

                }
                else if (d1.score > d2.score){
                    return -1;
                }else if(d1.age>d2.age){
                    return 1;
                }

                return 0;
            }
        });
        System.out.println("年龄从小到大排序为："+list);
        System.out.println("-------------------------");
        Collections.reverse(list);
        System.out.println("年龄从大到小 排序为："+list);



    }
}
class Student{
    public String name;
    public int age;
    public int score;
    public Student(String name,int age,int score){
        this.name=name;
        this.age=age;
        this.score=score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }
}
